import {LocalStorage} from 'quasar';
import {defaultAccount} from "src/lib/util/account";

const save = (state) => {
  LocalStorage.set('account', state);
}

export const updateAccessToken = (state, payload) => {
  update(state, {accessToken: payload});
}

export const updateRefreshToken = (state, payload) => {
  update(state, {refreshToken: payload});
}

export const update = (state, payload) => {
  for (const i in payload) {
    if (state.hasOwnProperty(i)) state[i] = payload[i];
  }
  save(state);
}

export const remove = (state) => {
  state = defaultAccount();
  save(state);
}
